package net.sourceforge.peertwitter.scamp.timers;


import net.sourceforge.peertwitter.scamp.Scamp;
import rice.p2p.commonapi.Id;
import rice.selector.TimerTask;


public class CheckHeartBeat extends TimerTask {

	private final Scamp scamp_MGRD;
	private final Id followed;

	public CheckHeartBeat(Scamp scamp_MGRD, Id followed) {
		this.scamp_MGRD = scamp_MGRD;
		this.followed = followed;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result
				+ ((followed == null) ? 0 : followed.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj) {
			return true;
		}
		if (obj == null) {
			return false;
		}
		if (getClass() != obj.getClass()) {
			return false;
		}
		CheckHeartBeat other = (CheckHeartBeat) obj;
		if (followed == null) {
			if (other.followed != null) {
				return false;
			}
		} else if (!followed.equals(other.followed)) {
			return false;
		}
		return true;
	}

	@Override
	public void run() {
		scamp_MGRD.rejoin(followed);
	}
	
	public CheckHeartBeat clone() {
		return new CheckHeartBeat(scamp_MGRD, followed);
	}
	
	
	
}